<?php
class Product extends Zend_Db_Table
{
	protected $_name ="product";
	protected $_primary = 'product_id';

    public function getAllProducts($page,$perpage,$search_name){
          $where = "1=1";
          if($search_name!=""){
              $where.=" and name like '%$search_name%'";
          }
          $select = $this->select();
          $select->where($where);
          if($page!=""){
          $select->limitPage($page,$perpage);
          }
         // return $select->__toString();
          $select->order('product_id desc');
          return $this->fetchAll($select)->toArray();
    }

    public function getAllProductsexcel(){
          $where = "1=1";

          $select = $this->select();
          $select->where($where);

         // return $select->__toString();
          $select->order('product_id asc');
          return $this->fetchAll($select)->toArray();
    }
 //根据id 查询product
    public function getproductByproduct_id($product_id){
          $select = $this->select();
          $select->where("product_id=".$product_id);
          return $this->fetchAll($select)->toArray();
    }


 //更新product
    public function updateproductByproduct_id($array,$product_id){
		$db = $this->getAdapter();
		$where=$db->quoteInto('product_id = ?', $product_id);
		$this->update($array, $where);
		return true;
	}
//删除product
	public function delproductByproduct_id($product_id){
          $where = 'product_id = '. $product_id;
         $this->delete($where);
         return true;
    }


}

